import 'package:flutter/material.dart';
import 'package:lib_uikit/lib_uikit.dart';
import 'package:lib_uikit/theme/gt_colors_v3.dart';
import 'package:lib_uikit/widgets/bottomsheet/gt_bottom_sheet.dart';

import '../text/gt_text.dart';

/// @Title   弹出标题内容文字列表bottomsheet
/// @Author: bryce
/// @CreateDate: 2023年10月18日16:09:54
Future<int?> showTitleContentListBottomSheet(
  context, {
  required List<GTTitleContentModel> titleContentList,
  int selectedIndex = -1,
  double? maxHeight, // bottomSheet最大高度
  double? minHeight, // bottomSheet最小高度
  // 下面的数据建议使用默认数值，符合规范
  double topPadding = 24, // child上边距
  double bottomPadding = 24, // child下边距，不是指cancel按钮下的边距
  double leftPadding = 16,
  double rightPadding = 16,
  double topRadius = 8.0, // bottomSheet上方圆角
  bool showBottomCancel = true, // 是否展示底部取消按钮
  bool showTopRightClose = false, // 是否展示右上角关闭按钮
  String? title,
}) async {
  return showGTBottomSheet(context,
      maxHeight: maxHeight,
      minHeight: minHeight,
      topPadding: topPadding,
      bottomPadding: bottomPadding,
      leftPadding: leftPadding,
      rightPadding: rightPadding,
      topRadius: topRadius,
      showBottomCancel: showBottomCancel,
      showTopRightClose: showTopRightClose,
      title: title,
      child: ListView.separated(
        shrinkWrap: true,
        physics: const BouncingScrollPhysics(),
        itemCount: titleContentList.length,
        separatorBuilder: (BuildContext context, int index) => const SizedBox(height: 8),
        itemBuilder: (BuildContext context, int index) {
          bool isSelected = index == selectedIndex;
          GTTitleContentModel item = titleContentList[index];
          return GestureDetector(
            onTap: () => Navigator.pop(context, index),
            behavior: HitTestBehavior.opaque,
            child: Container(
              decoration: BoxDecoration(
                  color: isSelected ? GTColorsV3.neutral2.color : GTColorsV3.card6.color,
                  borderRadius: BorderRadius.circular(3)),
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  TextUtils.isEmpty(item.title)
                      ? Container()
                      : GTText(item.title!,
                          style: TextStyle(
                              color: isSelected ? GTColorsV3.text5.color : GTColorsV3.text1.color,
                              fontSize: 14,
                              fontWeight: FontWeight.w500)),
                  SizedBox(height: TextUtils.isNotEmpty(item.title) ? 4 : 0),
                  TextUtils.isEmpty(item.content)
                      ? Container()
                      : GTText(item.content!,
                          style: TextStyle(color: GTColorsV3.text3.color, fontSize: 12, fontWeight: FontWeight.w400)),
                ],
              ),
            ),
          );
        },
      ));
}

class GTTitleContentModel {
  final String? title;
  final String? content;

  GTTitleContentModel({this.title, this.content});
}
